package main;

import java.util.ArrayList;

import unit.Unit;
import emergency.Emergency;

public class FacadeDispatcher extends Facade {
	
	public FacadeDispatcher(World world) {
		super(world);
	}

	public void assignAllUnits(Emergency emergency) {
		try{
			emergency.assignAllUnits(super.getWorld().getDispatchCenter().getGarage());
		}
		catch(Exception e){
			throw new IllegalArgumentException(e.toString());
		}
	}
	
	/**
	 * Assign an emergency to a unit and register the unit with the emergency
	 * that the emergency is being handled by the unit
	 * 
	 * @param emergency
	 *            The emergency that needs units to handle the emergency
	 * @param unit
	 *            The unit that will handle the given emergency
	 */
	public void assignUnit(Emergency emergency, Unit unit) {
		unit.assignEmergency(emergency);
	}

	/**
	 * cancel emergency
	 * emergency to this emergency
	 * 
	 * @param emergency
	 *            the emergency we'll try to cancel
	 * @return al list of strings of error messages from the units we couldn't cancel
	 *         null if emergency was canceled successful
	 */
	protected ArrayList<String> cancelEmergency(Emergency e){
		return e.cancelEmergency();
	}
	
	
	protected int getAantalUnits(String type){
		try{
			if(type==null){
				return super.getDispatchCenter().getAvailableUnits().size();
			}
			else{			
				return super.getDispatchCenter().getAvailableUnits(type).size();
			}
		}
		catch(Exception e){
			return 0;
		}
	}
	
	public void revokeUnit(Unit u) throws IllegalAccessException{
		u.revokeUnit();
	}

}
